<?php
class DepartmentModel extends Model{

	public function get_department_name_by_id($department_id)
	{
		return M('audience_department','','DB_MEETING')->where('department_id='.$department_id)->getField('department_name');
	}

	public function get_depart()
	{
		return M('Audience_department','','DB_MEETING')->where('time_insert > time_delete')->select();
	}


//城市查询
	public function get_local(){
		$sql = 'select * from meeting_roomlocal';
		return M('meeting_roomlocal','','DB_MEETING')->query($sql);
	}
//楼座查询
	public function get_build(){
		$sql = 'select * from meeting_roombuilding';
		return M('meeting_roombuild','','DB_MEETING')->query($sql);
	}
//楼层查询
	public function get_floor(){
		$sql = 'select * from meeting_roomfloor';
		return M('meeting_roomfloor','','DB_MEETING')->query($sql);
	}
//会议室所在地
	public function add_local($data){
		return M("meeting_roomlocal",'','DB_MEETING')->add($data);	
	}
//楼座
	public function add_build($data){
		return M("meeting_roombuilding",'','DB_MEETING')->add($data);
	}
//楼层
	public function add_floor($data){
		return M("meeting_roomfloor",'','DB_MEETING')->add($data);
	}
//添加会议室
	public function add_room($data){
		return M('meeting_room',"","DB_MEETING")->add($data);
	}
//查找id
	public function get_id($where){
		return M('meeting_room','','DB_MEETING')->where("room_id=".$where)->field("local_id,building_id,floor_id")->find();
	}
//删除回忆室
	public function del_room($where){
		return M('Meeting_room','','DB_MEETING')->where('room_id='.$where)->delete();
	}
//会议室查询
	public function find_room($data){
		return M('Meeting_room','','DB_MEETING')->where('room_id='.$data)->find();
	}
//城市条件查询
	public function find_local($data){
		return M('Meeting_roomlocal','','DB_MEETING')->where('local_id='.$data)->find();
	}
//楼座条件查询
	public function find_building($data){
		return M('Meeting_roombuilding','','DB_MEETING')->where('building_id='.$data)->find();
	}
//楼层条件查询
	public function find_floor($data){
		return M('Meeting_roomfloor','','DB_MEETING')->where('floor_id='.$data)->find();
	}
//会议室修改
	public function save_room($data){
		return M('Meeting_room','','DB_MEETING')->where('room_id='.$data['room_id'])->save($data);
	}
//部门条件查询
	public function find_depart($data){
		return M('Audience_department','','DB_MEETING')->where('department_id='.$data)->find();
	}
//部门查询

	public function update_department_rds_num($department_id)
	{
		return M('audience_department','','DB_MEETING')->where('department_id='.$department_id)->setInc('audience_num');;
	}

	public function update_department_time($department_id)
	{
		$data['time_update'] = time();
		return M('audience_department','','DB_MEETING')->where('department_id='.$department_id)->save($data);
	}
	public function update_department_personnel($data)
	{
		M('department_personnel','','DB_MEETING')->where('department_id='.$data['department_id'])->delete();

		$arr = explode(',',$data['personnel']);

		foreach($arr as $val)
		{
			$data1['department_id'] = $data['department_id'];
			$data1['personnel_id']  = $val;
			M('department_personnel','','DB_MEETING')->add($data1);
		}
	}

	public function get_department_personnel($department_id)
	{
		$rs = M('department_personnel','','DB_MEETING')->where('department_id='.$department_id)->select();
		$re='';
		foreach($rs as $val)
		{
			if($re == '')
				$re.= $val['personnel_id'];
			else
				$re.= ','.$val['personnel_id'];
		}
		return $re;
	}
	
	
	
}

?>